package cn.hx.fristgame;
/**
 * 飞机类
 */

import java.awt.*;
import java.awt.event.KeyEvent;

public class plane extends gameObj {

    boolean left,right,up,down;     //飞机方向变量

    public void drawSelf(Graphics g){   //方向控制
        g.drawImage(img,(int)x,(int)y,null);
        if (left){
            x -= speed;
        }
        if (right){
            x += speed;
        }
        if (up){
            y -= speed;
        }
        if (down){
            y += speed;
        }
    }
    public plane(Image img,double x,double y){  //变量接收
        this.img = img;
        this.x = x;
        this.y = y;

    }


    public void addDirection(KeyEvent e){   //按下某键增加相应的方向
        switch (e.getKeyCode()){
            case 37:
                left = true;
                break;
            case 38:
                up = true;
                break;
            case 39:
                right = true;
                break;
            case 40:
                down = true;
                break;
        }
    }
    public void minusDirection(KeyEvent e){   //取消按下某键,取消相应的方向
        switch (e.getKeyCode()){
            case 37:
                left = false;
                break;
            case 38:
                up = false;
                break;
            case 39:
                right = false;
                break;
            case 40:
                down = false;
                break;
        }
    }

}
